package cn.dengqiang.org.controller;

import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.basic.util.PageList;
import cn.dengqiang.org.domain.SystemDictionarydetail;
import cn.dengqiang.org.query.SystemDictionarydetailQuery;
import cn.dengqiang.org.service.ISystemDictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController   //=@ResponseBody+@Controller
@RequestMapping("/systemDictionarydetail")

@Api(tags = "品牌接口",description = "品牌接口详细描述")
public class SystemDictionarydetailController {

    @Autowired
    private ISystemDictionarydetailService systemDictionarydetailService;

    @PutMapping
    public AjaxResult save(@RequestBody SystemDictionarydetail systemDictionarydetail){
        try {
            if (systemDictionarydetail.getId()==null){
                systemDictionarydetailService.add(systemDictionarydetail);
            }else {
                systemDictionarydetailService.update(systemDictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("保存失败"+e.getMessage());
        }
    }




    @ApiOperation(value = "删除",notes = "根据id删除一条数据")
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            systemDictionarydetailService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
           return new AjaxResult("删除失败!"+e.getMessage());
       }
    }

    @ApiOperation(value = "查询",notes = "根据id查询一条数据")
    @GetMapping("/{id}") //根据id查询
    public SystemDictionarydetail getById(@PathVariable("id") Long id){
        return systemDictionarydetailService.getById(id);
    }

    @ApiOperation(value = "查询",notes = "查询所有信息")
    @GetMapping //systemDictionarydetail 查询所有
    public List<SystemDictionarydetail> getAll(){
        return systemDictionarydetailService.getAll();
    }

    @ApiOperation(value = "查询",notes = "分页查询")
    @PostMapping//分页查询
    public PageList<SystemDictionarydetail> list(@RequestBody SystemDictionarydetailQuery query){
        return systemDictionarydetailService.queryPage(query);
    }


    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        try {
            systemDictionarydetailService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("批量删除失败"+e.getMessage());
        }

    }

   
}
